package cn.liye.pingfen.controller;

import cn.liye.pingfen.pojo.dto.ComReviewsDTO;
import cn.liye.pingfen.pojo.dto.CompanyAddDTO;
import cn.liye.pingfen.pojo.dto.CompanyUpdateDTO;
import cn.liye.pingfen.pojo.vo.CompanyIndexVO;
import cn.liye.pingfen.pojo.vo.CompanyVO;
import cn.liye.pingfen.pojo.vo.TbZhiWeiVO;
import cn.liye.pingfen.response.JsonResult;
import cn.liye.pingfen.service.IComReviewsService;
import cn.liye.pingfen.service.ICompanyService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "公司模块")
@Validated
@Slf4j
@RestController
@RequestMapping("/v1/company")
public class CompanyController {

    @Autowired
    ICompanyService iCompanyService;

    @Autowired
    IComReviewsService iComReviewsService;

    @ApiOperation("新增公司信息")
    @PostMapping("/add")
    public JsonResult add(CompanyAddDTO companyAddDTO, ComReviewsDTO comReviewsDTO) {
        iCompanyService.insertCompany(companyAddDTO,comReviewsDTO);
        return JsonResult.ok();
    }

    @ApiOperation("搜索公司")
    @GetMapping("/list")
    public JsonResult list(String companyName, int pageNum, int pageSize) {
        PageInfo<CompanyVO> companyVO = iCompanyService.selectCompanyList(companyName,pageNum,pageSize);
        System.out.println(companyVO);
        return JsonResult.ok(companyVO);
    }

    @ApiOperation("获取所有公司详情")
    @GetMapping("/index")
    public JsonResult listForIndex(CompanyIndexVO companyIndexVO, int pageNum, int pageSize) {
        PageInfo<CompanyIndexVO> list = iCompanyService.selectCompanyListList(companyIndexVO,pageNum,pageSize);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询职位")
    @GetMapping("/zhiwei")
    public JsonResult ZhiWei(TbZhiWeiVO tbZhiWeiVO){
     List <TbZhiWeiVO>  list  = iCompanyService.selectZhiWeiList(tbZhiWeiVO);
        return JsonResult.ok(list);
    }

    @ApiOperation("计算评分")
    // 处理评分请求的方法
    @GetMapping("/calculate-score")
    public int calculateScore(@RequestParam double stars) {
        // 调用服务层的方法计算分数
        int score = iCompanyService.calculateScore(stars);
        // 返回分数
        return score;
    }


    @ApiOperation("获取平均分")
    @GetMapping("/aug")
    public JsonResult aug(CompanyUpdateDTO companyUpdateDTO){
        Double aug = iCompanyService.AUG(companyUpdateDTO);
        return JsonResult.ok(aug);
    }
}
